home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / launchpadbugs / text_buglist.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  4.4 KB  |  94 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''
  5. TODO:
  6.   * implement BugList.sort()
  7. '''
  8. import urlparse
  9. from bugbase import LPBugInfo, Bug as LPBug
  10. from buglistbase import LPBugList, LPBugPage
  11. from utils import valid_lp_url
  12. from lpconstants import BASEURL
  13. from lphelper import sort
  14.  
  15. class BugInfo(LPBugInfo):
  16.     
  17.     def __init__(self, nr, all_tasks):
  18.         LPBugInfo.__init__(self, nr, None, None, None, None, None, all_tasks)
  19.  
  20.  
  21.  
  22. class BugPage(LPBugPage):
  23.     '''
  24.     grab content of a single bug-table    
  25.     '''
  26.     
  27.     def find_parse_function(connection, url, all_tasks):
  28.         ''' this can extended to parse other listtypes (like
  29.             https://edge.launchpad.net/ubuntu/+milestone/gutsy-updates'''
  30.         url = valid_lp_url(url, BASEURL.BUGPAGE)
  31.         u = urlparse.urlsplit(url)
  32.         if u[2].endswith('+bugs-text'):
  33.             pass
  34.         elif u[2].endswith('+bugs'):
  35.             url = urlparse.urlunsplit((u[0], u[1], '%s-text' % u[2], u[3], u[4]))
  36.         else:
  37.             url = urlparse.urlunsplit((u[0], u[1], '%s/+bugs-text' % u[2], u[3], u[4]))
  38.         lp_content = connection.get(url)
  39.         result = BugPage.parse_text_bugpage(lp_content.text, all_tasks, url)
  40.         return result
  41.  
  42.     find_parse_function = staticmethod(find_parse_function)
  43.     
  44.     def parse_text_bugpage(text, all_tasks, url):
  45.         bugs = text.split('\n')
  46.         
  47.         def _parse():
  48.             for i in bugs:
  49.                 if i:
  50.                     yield BugInfo(i, all_tasks)
  51.                     continue
  52.             
  53.  
  54.         return (_parse(), False, len(bugs), len(bugs))
  55.  
  56.     parse_text_bugpage = staticmethod(parse_text_bugpage)
  57.  
  58.  
  59. class BugList(LPBugList):
  60.     '''
  61.     returns a SET of BugInfo objects
  62.     searches baseurl and its following pages
  63.     '''
  64.     
  65.     def __init__(self, baseurl, connection = None, all_tasks = False, progress_hook = None):
  66.         if hasattr(baseurl, 'baseurl'):
  67.             baseurl.baseurl = valid_lp_url(baseurl.baseurl, BASEURL.BUGLIST)
  68.         else:
  69.             baseurl = valid_lp_url(baseurl, BASEURL.BUGLIST)
  70.         LPBugList.__init__(self, baseurl, connection, all_tasks, BugPage, progress_hook)
  71.  
  72.     
  73.     def add(self, item):
  74.         if not isinstance(item, (LPBugInfo, LPBug)):
  75.             raise AssertionError
  76.         LPBugList.add(self, item)
  77.  
  78.     
  79.     def sort(self, optsort):
  80.         ''' returns a list of bug objects sorted by optsort
  81.         if one of the element in the list is an instance of LPBugInfo
  82.         the list can only be sorted by the bugnumber '''
  83.         attribute = optsort.strip('-')
  84.         m = filter((lambda x: isinstance(x, LPBugInfo)), self)
  85.         if m and not (attribute == 'nr'):
  86.             raise TypeError, 'text buglists containing LPBugInfo objects can only be sorted by nr'
  87.         not (attribute == 'nr')
  88.         
  89.         cmp_func = lambda x, y: sort(x, y, attribute)
  90.         isreverse = optsort.startswith('-')
  91.         return sorted(self, cmp = cmp_func, reverse = isreverse)
  92.  
  93.  
  94.